/**
 * @Project : ProgrammingExercises
 * @Package : Leetcode
 * @File : Q1290.java
 * @Author : WangRuoyu
 * @Date 2022/12/27 10:38
 */

package leetcode;

import util.LinkList;
import util.ListNode;

public class Q1290 {
    public int getDecimalValue(ListNode head) {
        int res = 0;

        while (head != null) {
            res = res * 2 + head.val;
            head = head.next;
        }

        return res;
    }

    public static void main(String[] args) {
        Q1290 sl = new Q1290();
        ListNode head = LinkList.createList(new int[]{1, 0, 1, 0, 1});
        System.out.println(sl.getDecimalValue(head));
    }
}
